<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Property_requirement_claims_controller
 *
 * @author wilson
 */
class PropertyRequirementClaimsController extends AppController {

    //put your code here
    var $name = "PropertyRequirementClaims";

    function edit($id) {
        if (empty($this->data)) {
            $textoRequerimiento = $this->PropertyRequirementClaim->query(
                    "SELECT Requirements.texto FROM property_requirement_claims PropertyRequirementClaim
                     LEFT JOIN property_requirements PropertyRequirement ON  PropertyRequirementClaim.property_requirement_id = PropertyRequirement.id
                     LEFT JOIN requirements Requirements ON PropertyRequirement.requirement_id = Requirements.id
                     WHERE PropertyRequirementClaim.id = $id"
            );
            $this->set('textoRequerimiento', $textoRequerimiento);

            $textoRequirementFault = $this->PropertyRequirementClaim->query(
                    "SELECT RequirementFault.nombre FROM property_requirement_claims PropertyRequirementClaim
                     LEFT JOIN property_requirements PropertyRequirement ON  PropertyRequirementClaim.property_requirement_id = PropertyRequirement.id
                     LEFT JOIN property_requirements_requirement_faults PropertyRequirementsRequirementFault ON
                     PropertyRequirementsRequirementFault.property_requirement_id = PropertyRequirement.id
                     LEFT JOIN requirement_faults RequirementFault ON RequirementFault.id = PropertyRequirementsRequirementFault.requirement_fault_id
                     WHERE PropertyRequirementClaim.id = $id"
            );
            $this->set('textoRequirementFault', $textoRequirementFault);

            $this->data = $this->PropertyRequirementClaim->find('first', array('conditions' => array('PropertyRequirementClaim.id' => $id),'fields'=>array('PropertyRequirementClaim.id','PropertyRequirementClaim.claim_id','PropertyRequirementClaim.calificacion','PropertyRequirementClaim.concepto')));
        } else {
            if ($this->PropertyRequirementClaim->saveAll($this->data)) {
                $this->Session->setFlash('Reclamacion editada con éxito');
                $this->redirect(array('controller' => 'Claims', 'action' => 'total_index', $this->data['PropertyRequirementClaim']['claim_id']));
            }
        }
    }
    
    
     function recalification($id) {
        if (empty($this->data)) {
            $textoRequerimiento = $this->PropertyRequirementClaim->query(
                    "SELECT Requirements.texto FROM property_requirement_claims PropertyRequirementClaim
                     LEFT JOIN property_requirements PropertyRequirement ON  PropertyRequirementClaim.property_requirement_id = PropertyRequirement.id
                     LEFT JOIN requirements Requirements ON PropertyRequirement.requirement_id = Requirements.id
                     WHERE PropertyRequirementClaim.id = $id"
            );
            $this->set('textoRequerimiento', $textoRequerimiento);

            $textoRequirementFault = $this->PropertyRequirementClaim->query(
                    "SELECT RequirementFault.nombre FROM property_requirement_claims PropertyRequirementClaim
                     LEFT JOIN property_requirements PropertyRequirement ON  PropertyRequirementClaim.property_requirement_id = PropertyRequirement.id
                     LEFT JOIN property_requirements_requirement_faults PropertyRequirementsRequirementFault ON
                     PropertyRequirementsRequirementFault.property_requirement_id = PropertyRequirement.id
                     LEFT JOIN requirement_faults RequirementFault ON RequirementFault.id = PropertyRequirementsRequirementFault.requirement_fault_id
                     WHERE PropertyRequirementClaim.id = $id"
            );
            $this->set('textoRequirementFault', $textoRequirementFault);

            $this->data = $this->PropertyRequirementClaim->find('first', array('conditions' => array('PropertyRequirementClaim.id' => $id),'fields'=>array('PropertyRequirementClaim.id','PropertyRequirementClaim.claim_id','PropertyRequirementClaim.calificacion_territorial','PropertyRequirementClaim.concepto_territorial')));
        } else {
            if ($this->PropertyRequirementClaim->saveAll($this->data)) {
                $this->Session->setFlash('Reclamacion editada con éxito');
                $this->redirect(array('controller' => 'Claims', 'action' => 'recalification_index', $this->data['PropertyRequirementClaim']['claim_id']));
            }else{
                $this->Session->setFlash('Error');
            }
        }
    }
    

}

?>
